package com.taoyun.web.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.taoyun.pojo.entity.File;
import com.taoyun.pojo.entity.Group;
import com.taoyun.pojo.entity.User;
import com.taoyun.pojo.vo.GroupVO;
import com.taoyun.pojo.vo.UserVO;
import com.taoyun.service.IObsService;
import com.taoyun.service.IUserService;
import com.taoyun.utils.ExcelUtils;
import com.taoyun.utils.Response;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.*;

@RestController
public class UserController {
    @Autowired
    private IUserService userService;

    @Autowired
    private IObsService obsService;

    //@PostMapping("taoyun/v1/test")
    //public Response delete_Obsobject(String objectName)  throws IOException{
    //    return Response.success(obsService.delete_Obsobject(objectName));
    //}

    /**
     * 以下属于超管操作
     * url: /taoyun/v1/SAdmin/userManage/加上具体操作名称
     */

    /**
     * 超管提升某个员工为部门管理员
     * http://localhost:8080/taoyun/v1/SAdmin/userManage/PromoteToAdmin
     * @param AdminId  （必须）操作者Id（对应数据库User_Id）
     * @param userId  （必须）被操作的Id(对应数据库User_Id)
     * @return
     *  {
    "code": "200",
    "msg": "请求成功",
    "data": null
    }
     */
    @GetMapping("taoyun/v1/SAdmin/userManage/PromotedToAdmin")
    public Response PromotedToAdmin(@RequestParam("AdminId") Integer AdminId, @RequestParam("userId") Integer userId){
        if(AdminId!=null && userId!=null){
            if(userService.getUserById(AdminId).getPermission().equals("超管")){
                String Department = userService.getUserById(userId).getDepartment(); //获取被操作员工的部门
                List<User> Admins = userService.AdminExist(Department,"管理员");  //判断是否已存在管理员
                if(Admins.size()==1){ //存在，先降级原来的管理员，再提升该员工为部门管理员
                    userService.Demotion(Department); //先获取user，再操作
                    userService.Promoted(userId);
                    return Response.success("已成功提升为管理员!");
                }else{//不存在，直接提升为管理员
                    userService.Promoted(userId);
                    return Response.success("已成功提升为管理员！");
                }
            }else{
                return Response.error("不好意思，您不是超管，无法执行该操作!");
            }
        }else if(AdminId==null && userId!=null){
            return Response.error("传入的AdminId为空!");
        }else{
            return Response.error("传入的userId为空!");
        }
    }

    /**
     * 超管查询全部员工（包括管理员）,除去自己
     * http://localhost:8080/taoyun/v1/SAdmin/userManage/ShowAll
     * @param Id    超管Id
     * @return  List<User> users    用户列表对象
     *   {
    "code": "200",
    "msg": "以下是涛云网盘的所有用户：",
    "data": [****]
    }
     */
    @GetMapping("taoyun/v1/SAdmin/userManage/ShowAll")
    public Response ShowAll(@RequestParam(value = "page", defaultValue = "1") Integer page,
                            @RequestParam(value = "size",defaultValue = "8")Integer size,@RequestParam("Id") Integer Id){
        if(Id != null && userService.getUserById(Id).getPermission().equals("超管")){ //先判断是否为超管查询所有用户
            PageHelper.startPage(page,size,true);
            List<User> userList = userService.ShowAll(Id); //添加ShowAll方法
            PageInfo<User> pageInfo = new PageInfo<>(userList);
            if(userList != null){
                return Response.success("以下是涛云网盘的所有用户：", pageInfo);
            }else{
                return Response.error("尊敬的超管，您好！未查询到云盘用户，请先为云盘添加用户再尝试查询！");
            }
        }else if(Id != null && !(userService.getUserById(Id).getPermission().equals("超管"))){
            return Response.error("不好意思，您不是该云盘的超管，无法查询全部用户信息！");
        }else{
            return Response.error("未能判断您的身份，暂时不能进行查看所有员工操作！");
        }
    }

    /**
     * @Title: 超管单个添加员工
     * http://localhost:8080/taoyun/v1/SAdmin/userManage/AddUser
     * @Description：页面表单传入信息
     * @param  user 添加的用户User对象信息
     * @return String
     * {
    "code": "200",
    "msg": "请求成功",
    "data": null
    }
     */
    @PostMapping("taoyun/v1/SAdmin/userManage/AddUser")
    public Response AddUser(@RequestParam("AdminId") Integer AdminId,@RequestBody User user) throws IOException {
        if (user != null && AdminId != null) {
            if(userService.getUserById(AdminId).getPermission().equals("超管")) {
                if (userService.SelectUserByUserNumber(user.getUserNumber()) == 0) {//工号不存在，可添加
                    if (user.getPermission().equals("管理员")) {  //判断：如果添加的是管理员，就先判断该部门是否已经存在管理员
                        List<User> Admins = userService.AdminExist(user.getDepartment(), "管理员");
                        if (Admins.size() == 0) {
                            int result = userService.AddUser(user);
                            if (result == 1) {
                                return Response.success("添加管理员成功。");
                            } else {
                                return Response.error("用户信息不完整！");
                            }
                        } else {
                            return Response.error("该部门已设置了管理员！");
                        }
                    } else { //不是添加管理员，只是添加普通员工
                        int result = userService.AddUser(user);
                        if (result == 1) {
                            return Response.success("添加员工成功！");
                        } else {
                            return Response.error("添加用户失败，请检查！");
                        }
                    }
                } else {
                    return Response.error("不好意思，该UserNumber已存在，请更换！");
                }
            }else{
                return Response.error("不好意思，您不是超管，无法执行该操作！");
            }
        }else if(user!=null && AdminId==null){
            return Response.error("传入参数AdminId为空！");
        }else{
            return Response.error("传入的user对象为空！");
        }
    }

    /**
     * 超管批量添加员工
     * http://localhost:8080/taoyun/v1/SAdmin/userManage/AddUserBatch
     * @Description：excel导入
     * @param file  excel表格文件
     * @param Id 超管id
     * @return String
     */
    @PostMapping("taoyun/v1/SAdmin/userManage/AddUserBatch")
    public Response SAddUserBatch(@RequestParam("file") MultipartFile file, @Param("Id") Integer Id) throws IOException {
        List<User> users = ExcelUtils.importData(file, 1, User.class);
        if(userService.getUserById(Id).getPermission().equals("超管")){
            if(users != null && !users.isEmpty()){
                if(userService.SelectUserByUserNumberList(users)==0) {//工号不存在，可添加
                    if (userService.AddStaffsBatch(users) == users.size()) {
                        return Response.success();
                    } else {
                        return Response.error("添加失败，部分数据未添加！");
                    }
                }else{
                    return Response.error("工号已存在，请更换！");
                }
            }else{
                return Response.error("传入数据为空，请检查数据是否正确！");
            }
        }else{
            return Response.error("您不是超管，无法执行该操作！");
        }
    }

    /**
     * 超管删除单个用户
     * http://localhost:8080/taoyun/v1/SAdmin/userManage/deleteUser
     * @param AdminId   超管id
     * @param userId    被删除用户的id
     * @return Response
     * {
    "code": "200",
    "msg": "请求成功",
    "data": null
    }
     */
    @DeleteMapping("taoyun/v1/SAdmin/userManage/deleteUser")
    public Response DeleteUser(@Param("AdminId") Integer AdminId, @Param("userId") Integer userId){
        if(AdminId != null && userId != null){
            List<Integer> Ids = new ArrayList<>();
            Ids.add(userId);
            if(userService.getUserById(AdminId).getPermission().equals("超管")){
                if(userService.BanState(Ids)==Ids.size()){
                    if(userService.DeleteUser(userId) == 1) {
                        return Response.success();
                    }else{
                        return Response.error("删除失败！");
                    }
                }else{
                    return Response.error("删除用户前的冻结操作失败!");
                }
            }else{
                return Response.error("您不是超管，无法执行该操作！");
            }
        }else{
            return Response.error("传入参数为空！");
        }
    }

    /**
     * 超管批量删除用户
     * http://localhost:8080/taoyun/v1/SAdmin/userManage/DeleteUserBatch
     * @param  AdminId 超管id
     * @param ids   被删除的用户的id数组
     *      传参示例：AdminId=16&ids=12,13,14
     * @return Response
     * {
    "code": "200",
    "msg": "请求成功",
    "data": null
    }
     */
    @DeleteMapping("taoyun/v1/SAdmin/userManage/DeleteUserBatch")
    public Response DeleteUserBatch(@RequestParam(value = "ids", required = false) Integer[] ids, @Param("AdminId") Integer AdminId){
        if(AdminId != null && ids.length != 0 && userService.getUserById(AdminId).getPermission().equals("超管")){
            if(userService.DeleteUserBatch(ids) == 1){
                return Response.success("删除成功！");
            }else{
                return Response.error("删除失败！");
            }
        }else if(AdminId != null && ids.length != 0 && !(userService.getUserById(AdminId).getPermission().equals("超管"))){
            return Response.error("您不是超管，无法执行该操作!");
        }else if(AdminId != null && ids.length ==0 && userService.getUserById(AdminId).getPermission().equals("超管")){
            return Response.error("ids数组为空，请输入！");
        }else{
            return Response.error("AdminId为空，无法判断您的身份！");
        }
    }

    /**
     * 超管修改员工信息，接收前端传来的员工userId和超管AdminId，把员工信息传送到修改页面
     * @param IdMap
     * {
     *     "AdminId":16,
     *     "userId":67
     * }
     * @return
     */
    @PutMapping("taoyun/v1/SAdmin/userManage/ToModifyUserInformation")
    public Response ModifyUserById(@RequestBody Map IdMap) {
        if (!"".equals(IdMap.get("AdminId").toString()) && !"".equals(IdMap.get("userId").toString())) {
            Integer AdminId;
            Integer userId;
            AdminId = ((Number) IdMap.get("AdminId")).intValue();
            User Admin = userService.getUserById(AdminId);
            userId = ((Number) IdMap.get("userId")).intValue();
            User user = userService.getUserById(userId);
            if (user != null && Admin.getPermission().equals("超管")) {
                return Response.success("请求成功，返回Id为:" + userId + "的员工信息。", user);
            } else if (user != null && !(Admin.getPermission().equals("超管"))) {
                return Response.error("不好意思，您不是超管，无法执行该操作！");
            } else {
                return Response.error("数据库中不存在该员工信息，请确认输入正确！");
            }
        }else if(!"".equals(IdMap.get("AdminId").toString()) && "".equals(IdMap.get("userId").toString())){
            return Response.error("userId为空！请检查！");
        }else if("".equals(IdMap.get("AdminId").toString()) && !"".equals(IdMap.get("userId").toString())){
            return Response.error("AdminId为空！请检查");
        }else{
            return Response.error("userId和AdminId参数丢失，为空！");
        }
    }

    /**
     * 超管修改单个员工信息，全权限
     * http://localhost:8080/taoyun/v1/SAdmin/userManage/ModifyUserInformation
     * @Param user  修改的目标用户对象
     * @Param AdminId   超管id
     * @return
     */
    //postman测试在Body的raw中用json传
    @PostMapping("taoyun/v1/SAdmin/userManage/ModifyUserInformation")
    public Response ModifyUserInformation(@RequestBody User user, @Param("AdminId") Integer AdminId){
        if(AdminId != null && user != null){
            int id = user.getUserId();  //获取被修改者的userId
            Boolean identity = userService.getUserById(AdminId).getPermission().equals("超管");
            if(identity){
                if(userService.SAdminModify(user)==1){
                    return Response.success("修改成功！", userService.getUserById(id)); //返回已修改的结果
                }else{
                    return Response.error("修改失败！");
                }
            }else{
                return Response.error("不好意思，您不是超管，无法执行该操作！");
            }
        }else if(AdminId != null && user == null){
            return Response.error("传入的user为空！");
        }else{
            return Response.error("传入的AdminId为空，无法判断您的身份！");
        }
    }

    /**
     * 超管一键重置所有员工的密码，重置后密码为空
     * http://localhost:8080/taoyun/v1/SAdmin/userManage/ResetAllPassword
     * @param AdminId   超管id
     * @Return
     */
    @PostMapping("taoyun/v1/SAdmin/userManage/ResetAllPassword")
    public Response ResetAllPassword(@Param("AdminId")Integer AdminId){
        if(AdminId != null){
            int result = userService.ResetAllPassword(AdminId);
            if(result == 1){
                return Response.success("重置密码成功！");
            }else if(result == -1){
                return Response.error("您不是超管，无法执行该操作!");
            }else{
                return Response.error("没有该用户，不能执行操作！");
            }
        }else {
            return Response.error("传入参数为空！无法判断您的身份！");
        }
    }

    /**
     * 超管允许用户使用云盘
     * @param AdminId
     * @param Ids
     * 传参示例：[67,68,69]
     * @return
     * {
     *     "code": "200",
     *     "msg": "请求成功",
     *     "data": "已成功！"
     * }
     */
    @PutMapping("taoyun/v1/SAdmin/userManage/AllowState")
    public Response AllowState(@RequestParam("AdminId") Integer AdminId, @RequestBody List<Integer> Ids){
        User Admin = userService.getUserById(AdminId);
        if(Admin.getPermission().equals("超管") && Ids.size() != 0){
            userService.AllowState(Ids);
            return Response.success("已成功！");
        }else if(!Admin.getPermission().equals("超管") && Ids.size() != 0){
            return Response.error("不好意思，您不是超管，无法执行该操作！");
        }else{
            return Response.error("Ids丢失！");
        }
    }

    /**
     * 超管禁止用户使用云盘
     * @param AdminId
     * @param Ids
     * 传参示例：[67,68,69]
     * @return
     * {
     *     "code": "200",
     *     "msg": "请求成功",
     *     "data": "已成功！"
     * }
     */
    @PutMapping("taoyun/v1/SAdmin/userManage/BanState")
    public Response BanState(@RequestParam("AdminId") Integer AdminId,@RequestBody List<Integer> Ids){
        User Admin = userService.getUserById(AdminId);
        if(Admin.getPermission().equals("超管") && Ids.size() != 0){
            userService.BanState(Ids);
            return Response.success("已成功！");
        }else if(!Admin.getPermission().equals("超管") && Ids.size() != 0){
            return Response.error("不好意思，您不是超管，无法执行该操作！");
        }else{
            return Response.error("Ids丢失");
        }
    }

    /**
     * 以下属于管理员操作
     */

    /**
     * @Title: 管理员单个添加员工
     * http://localhost:8080/taoyun/v1/Admin/userManage/AddUser
     * @Description：页面表单传入信息
     * @param  user 添加的员工(User)对象信息
     * @param Id 管理员id
     * @return String
     */
    @PostMapping("taoyun/v1/Admin/userManage/AddUser")
    public Response AddUser1(@Param("Id") Integer Id, @RequestBody User user ) throws IOException {
        if(Id != null && user != null){
            if(userService.SelectUserByUserNumber(user.getUserNumber())==0) { //工号不存在，可添加
                User Admin = userService.getUserById(Id);
                Boolean result = userService.SameDepartment(Id, user.getDepartment());
                Boolean result1 = Admin.getPermission().equals("管理员");
                if (result && result1) {
                    userService.AddUser(user);
                    return Response.success("添加成功！");
                } else if (result && !result1) {
                    return Response.error("您不是该部门的管理员，无法执行该操作！");
                } else {
                    return Response.error("不好意思，您作为" + userService.getUserById(Id).getDepartment() + "的管理员，只能添加自己部门的员工！" +
                            "您现在添加的员工部门为：" + user.getDepartment());
                }
            }else{
                return Response.error("工号已存在，请更换！");
            }
        }else if(Id!=null && user == null){
            return Response.error("传入的user为空！");
        }else{
            return Response.error("传入的Id为空！");
        }
    }

    /**
     * 管理员批量导入自己部门的员工
     * http://localhost:8080/taoyun/v1/Admin/userManage/AddUserBatch
     */
    @PostMapping("taoyun/v1/Admin/userManage/AddUserBatch")
    public Response AddUserBatch(@RequestParam("file") MultipartFile file, @Param("Id") Integer Id) throws IOException {
        List<User> users = ExcelUtils.importData(file, 1, User.class);
        if(userService.getUserById(Id).getPermission().equals("管理员")){
            if(users != null && !users.isEmpty()) {
                if(userService.SelectUserByUserNumberList(users)==0){ //工号不存在，可添加
                    if (userService.AddStaffsBatch(users) == users.size()) {
                        return Response.success();
                    } else {
                        return Response.error("添加不完整，部分数据未添加！");
                    }
                }else{
                    return Response.error("工号已存在，添加失败！");
                }
            }else{
                return Response.error("传入数据为空，请检查数据是否正确！");
            }
        }else{
            return Response.error("您不是该部门的管理员，无法执行该操作！");
        }
    }

    /**
     * 管理员单个删除自己部门的员工
     * http://localhost:8080/taoyun/v1/Admin/userManage/DeleteUser
     */
    @DeleteMapping("taoyun/v1/Admin/userManage/DeleteUser")
    public Response DeleteUser1(@Param("AdminId") Integer AdminId, @Param("userId") Integer userId){
        if(AdminId != null && userId != null){
            User Admin = userService.getUserById(AdminId);
            User user = userService.getUserById(userId);
            String uDepartment = user.getDepartment();
            Boolean result = userService.SameDepartment(AdminId, uDepartment);
            Boolean result1 = Admin.getPermission().equals("管理员");
            if(result && result1){
                userService.DeleteUser(userId);
                return Response.success("删除成功！");
            }else if(result && !result1){
                return Response.error("您不是管理员！");
            }else{
                return Response.error("您不能删除不属于自己部门的员工！");
            }
        }else{
            return Response.error("传入的参数为空!");
        }
    }

    /**
     * 管理员批量删除员工  AdminId=41&ids=43
     * http://localhost:8080/taoyun/v1/Admin/userManage/DeleteUserBatch
     */
    @DeleteMapping("taoyun/v1/Admin/userManage/DeleteUserBatch")
    public Response DeleteStaffsBatch(@RequestParam(value = "ids", required = false) Integer[] ids, @Param("AdminId") Integer AdminId){
        Boolean result = userService.getUserById(AdminId).getPermission().equals("管理员");
        if(AdminId != null && ids.length != 0 && result){
            if(userService.DeleteUserBatch(ids) == 1){
                return Response.success("删除成功");
            }else{
                return Response.error("删除失败！");
            }
        }else if(AdminId != null && ids.length != 0 && !result){
            return Response.error("您不是管理员，无法执行该操作!");
        }else if(AdminId != null && ids.length ==0 && result){
            return Response.error("ids数组为空，请输入！");
        }else{
            return Response.error("AdminId为空，无法判断您的身份！");
        }
    }

    /**
     * 管理员修改员工信息 全权限  raw写user
     * http://localhost:8080/taoyun/v1/Admin/userManage/ModifyUserInformation
     * @param AdminId
     * @param user
     * @return
     */
    @PostMapping("taoyun/v1/Admin/userManage/ModifyUserInformation")
    public Response ModifyUserInformation1(@RequestBody User user, @Param("AdminId") Integer AdminId) {
        if(AdminId != null && user != null){
            int id = user.getUserId();  //获取被修改者的userId
            Boolean identity = userService.getUserById(AdminId).getPermission().equals("管理员");
            Boolean sameDepart = userService.SameDepartment(AdminId, user.getDepartment());
            if(identity && sameDepart){
                if(userService.SAdminModify(user)==1){
                    return Response.success("修改成功！", userService.getUserById(id)); //返回已修改的结果
                }else{
                    return Response.error("修改失败！");
                }
            }else if(identity && !sameDepart){
                return Response.error("不好意思，您不能修改不属于您部门的员工信息！");
            }else{
                return Response.error("不好意思，您不是管理员！无法执行该操作！");
            }
        }else if(AdminId != null && user == null){
            return Response.error("传入的user为空！");
        }else{
            return Response.error("传入的AdminId为空，无法判断您的身份！");
        }
    }

    /**
     * 查询部门内员工
     * http://localhost:8080/taoyun/v1/Admin/userManage/ShowAllUserByDepart
     * @param Department
     * @return
     */
    @GetMapping("taoyun/v1/Admin/userManage/ShowAllUserByDepart")
    public Response ShowAllUserByDepart(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                        @RequestParam(value = "size",defaultValue = "8")Integer size,@RequestParam(value = "Department") String Department) throws IOException {
        Department = URLDecoder.decode(Department, "utf-8");
        if(!Department.equals("")){
            PageHelper.startPage(page,size,true);
            List<User> users = userService.SearchStaffByDepartment(Department);
            PageInfo<User> pageInfo = new PageInfo<>(users);
            if(users.size() != 0){
                return Response.success("查找到" + Department + "的员工:", pageInfo);
            }else {
                return Response.error("查找不到'" + Department + "'的员工，请先为自己的部门添加员工的信息！");
            }
        }else {
            return Response.error("传入参数为空");
        }
    }

    /**
     *  根据ID查找员工
     *  http://localhost:8080/taoyun/v1/Admin/userManage/SearchUserByID
     */
    @GetMapping("taoyun/v1/Admin/userManage/SearchUserByID")
    public Response SearchUserByID(@RequestParam(value = "id") Integer id){
        if(id != null){
            User user = userService.getUserById(id);
            if(user != null){
                return Response.success("查找成功",user);
            }else {
                return Response.error("查找不到id为"+id+"的用户");
            }
        }else {
            return Response.error("查找失败，传入参数为空");
        }
    }

    /**
     * 根据姓名对员工的模糊查询
     * http://localhost:8080/taoyun/v1/Admin/userManage/SearchStaffByName
     * @param name
     * @return
     */
    @GetMapping("taoyun/v1/Admin/userManage/SearchStaffByName")
    public Response SearchStaffByName(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                      @RequestParam(value = "size",defaultValue = "8")Integer size,@RequestParam(value = "name") String name,@RequestParam("Department") String Department) throws IOException {
        Department = URLDecoder.decode(Department, "utf-8");
        PageHelper.startPage(page,size,true);
        List<User> users = userService.SearchStaffByName("%"+name+"%","%"+Department+"%");
        PageInfo<User> pageInfo = new PageInfo<>(users);
        if(users.size() != 0){
            return Response.success("查找成功", pageInfo);
        }else {
            return Response.error("查找不到name为"+name+"的用户");
        }

    }



    /**
     * 以下是个人信息操作
     */

    /**
     * 员工查询自己的信息
     * @param Id
     * @return
     */
    @GetMapping("taoyun/v1/User/PersonalInformation")
    public Response PersonalInformation(@RequestParam("Id") Integer Id){
        if(Id != null && userService.getUserById(Id)!=null){
            User user = userService.getUserById(Id);
            return Response.success("以下是您的个人信息：", user);
        }else if(Id!=null && userService.getUserById(Id) == null){
            return Response.error("未能查找到您的信息！");
        }else{
            return Response.error("Id为空！");
        }
    }

    /**
     *  个人信息管理（包括超管、管理员、员工），只能修改密码，邮箱，手机号 raw
     * @param userVO
     * @return
     */
    @PostMapping("taoyun/v1/User/ModifyInformation")
    public Response UserModifyInformation(@RequestBody UserVO userVO){
        if(userVO != null){
            Integer result = userService.UpdateStaffs(userVO);
            if(result != 0){
                return Response.success("修改成功",userVO);
            }else {
                return Response.error("修改失败");
            }
        }else {
            return Response.error("传入参数为空");
        }
    }

    /**
     * 修改密码。将用户输入的邮箱与数据库中的邮箱信息进行判断
     * @param userId
     * @param password
     * @param email
     * @return
     */
    @PutMapping("taoyun/v1/User/UserUpdatePwd")
    public Response UserUpdatePwd(Integer userId, String password, String email){
        if(userId != null && !password.equals("") && !email.equals("")){
            Integer result = userService.StaffUpdatePwd(userId, password, email);
            if(result == 1){
                return Response.success("密码更新成功");
            }else {
                return Response.error("修改失败，输入邮箱错误");
            }
        }else {
            return Response.error("传入参数为空");
        }
    }


    /**
     * 用于数据验证
     * @param users
     * @param response
     * @return
     */
    public Map<String,String> Valid(List<User> users,HttpServletResponse response){
            Map<String,String> ErrorMap = new HashMap<>();
            ErrorMap = userService.NoNUll(users,response);
            if(ErrorMap.isEmpty() && ErrorMap.size()==0){  //判断是否有错误信息
                //没有错误信息返回成功信息
                return null;
            }else{
                //返回错误信息
                return ErrorMap;
            }
    }


}
